package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListDemo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("therr");
        list.add("four");
        list.add("five");
        System.out.println("1" + list);

        String e = list.get(2);
        System.out.println(e);

        for (int i = 0; i < list.size(); i++) {
            e = list.get(i);
            System.out.println(e);
        }
        String old = list.set(2, "six");
        System.out.println(list);
        System.out.println("被替换的元素是" + old);

        //基于get和set操作，将集合元素反转
        for (int i = 0; i < list.size() / 2; i++) {
         /*   //将正数位置的元素获取到
            String s = list.get(i);
            //将该元素设置到对应的倒数位置上
            s = list.set(list.size()-1-i,s);
            //将原倒数位置的元素设置到整数位置上
            list.set(i,s);*/

            list.set(i, list.set(list.size() - 1 - i, list.get(i)));
        }
        //[five,four,six,two,one]
        System.out.println(list);

        //反转集合
        Collections.reverse(list);
        System.out.println(list);

    }


}

